package test;

import java.io.*;

/**
 * Created by Caesar on 2015/11/19.
 */
public class Income {
    int age = 0;
    int workclass = 0;
    int fnlwgt = 0;
    int education = 0;
    int education_num = 0;
    int marital_status = 0;
    int occupation = 0;
    int relationship = 0;
    int race = 0;
    int sex = 0;
    int capital_gain = 0;
    int capital_loss = 0;
    int hours_per_week = 0;
    int native_country = 0;
    int is5K = 0;

    public Income(int age, int workclass, int fnlwgt, int education, int education_num, int marital_status, int occupation,
                  int relationship, int race, int sex, int capital_gain, int capital_loss, int hours_per_week,
                  int native_country, int is5K) {
        this.age = age;
        this.workclass = workclass;
        this.education = education;
        this.fnlwgt = fnlwgt;
        this.education_num = education_num;
        this.marital_status = marital_status;
        this.occupation = occupation;
        this.relationship = relationship;
        this.race = race;
        this.sex = sex;
        this.capital_gain = capital_gain;
        this.capital_loss = capital_loss;
        this.hours_per_week = hours_per_week;
        this.native_country = native_country;
        this.is5K = is5K;
    }

    public static void main(String[] args) {
        File file = new File("D:\\data\\adult.txt");
        if (file.isFile() && file.exists()) { //判断文件是否存在
            InputStreamReader read = null;//考虑到编码格式
            try {
                read = new InputStreamReader(
                        new FileInputStream(file));
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = null;
/*                while ((lineTxt = bufferedReader.readLine()) != null) {
                    System.out.println(lineTxt);
                }*/
                lineTxt = bufferedReader.readLine();
                String[] lines = lineTxt.split(",");
                Income in = new Income(Integer.parseInt(lines[0]), work(lines[1].trim()), Integer.parseInt(lines[2].trim()),
                        education(lines[3].trim()), Integer.parseInt(lines[4].trim()), marital(lines[5].trim()),
                        occupation(lines[6].trim()), relationship(lines[7].trim()), race(lines[8].trim()), sex(lines[9].trim()),
                        Integer.parseInt(lines[10].trim()), Integer.parseInt(lines[11].trim()), Integer.parseInt(lines[12].trim()),
                        native_country(lines[13].trim()), is5K(lines[14].substring(1, 2)));
                read.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static int work(String work) {
        switch (work) {
            case "Private":
                return 1;
            case "Self-emp-not-inc":
                return 2;
            case "Self-emp-inc":
                return 3;
            case "Federal-gov":
                return 4;
            case "Local-gov":
                return 5;
            case "State-gov":
                return 6;
            case "Without-pay":
                return 7;
            case "Never-worked":
                return 8;
            default:
                return 0;
        }
    }

    public static int education(String education_status) {
        switch (education_status) {
            case "bachelosrs":
                return 1;
            case "some-college":
                return 2;
            case "11th":
                return 3;
            case "HS-grad":
                return 4;
            case "Assoc-acdm":
                return 5;
            case "Assoc-voc":
                return 6;
            case "9th":
                return 7;
            case "7th-8th":
                return 8;
            case "12th":
                return 9;
            case "Masters":
                return 10;
            case "1st-4th":
                return 11;
            case "10th":
                return 12;
            case "Doctorate":
                return 13;
            case "5th-6th":
                return 14;
            case "Preschool":
                return 15;
            default:
                return 0;
        }

    }

    public static int marital(String marital_status) {
        switch (marital_status) {
            case "Married-civ-spouse":
                return 1;
            case "Divorced":
                return 2;
            case "Never-married":
                return 3;
            case "Widowed":
                return 4;
            case "Married-spouse-absent":
                return 5;
            case "Married-AF-spouse":
                return 6;
            default:
                return 0;
        }
    }

    public static int occupation(String job) {
        switch (job) {
            case "Tech-support":
                return 1;
            case "Craft-repair":
                return 2;
            case "Other-service":
                return 3;
            case "Sales":
                return 4;
            case "Exec-managerial":
                return 5;
            case "Prof-specialty":
                return 6;
            case "Handlers-cleaners":
                return 7;
            case "Machine-op-inspct":
                return 8;
            case "Adm-clerical":
                return 9;
            case "Farming-fishing":
                return 10;
            case "Transport-moving":
                return 11;
            case "Priv-house-serv":
                return 12;
            case "Protective-serv":
                return 13;
            case "Armed-Forces":
                return 14;
            default:
                return 0;
        }

    }

    public static int relationship(String rel) {
        switch (rel) {
            case "Wife":
                return 1;
            case "Own-child":
                return 2;
            case "Husband":
                return 3;
            case "Not-in-family":
                return 4;
            case "Other-relative":
                return 5;
            case "Unmarried":
                return 6;
            default:
                return 0;
        }

    }

    public static int race(String ra) {
        switch (ra) {
            case "White":
                return 1;
            case "Asian-Pac-Islander":
                return 2;
            case "Amer-Indian-Eskimo":
                return 3;
            case "Other":
                return 4;
            case "Black":
                return 5;
            default:
                return 0;
        }

    }

    public static int sex(String se) {
        switch (se) {
            case "Female":
                return 1;
            case "Male":
                return 2;
            default:
                return 0;
        }

    }

    public static int native_country(String country) {
        switch (country) {
            case "United-States":
                return 1;
            case "Cambodia":
                return 2;
            case "England":
                return 3;
            case "Puerto-RicoOther":
                return 4;
            case "Canada":
                return 5;
            case "Germany":
                return 6;
            case "Outlying-US(Guam-USVI-etc)":
                return 7;
            case "India":
                return 8;
            case "Japan":
                return 9;
            case "Greece":
                return 10;
            case "South":
                return 11;
            case "China":
                return 12;
            case "Cuba":
                return 13;
            case "Iran":
                return 14;
            case "Honduras":
                return 15;
            case "Philippines":
                return 16;
            case "Italy":
                return 17;
            case "Poland":
                return 18;
            case "Jamaica":
                return 19;
            case "Vietnam":
                return 20;
            case "Mexico":
                return 21;
            case "Portugal":
                return 22;
            case "Ireland":
                return 23;
            case "France":
                return 24;
            case "Dominican-Republic":
                return 25;
            case "Laos":
                return 26;
            case "Ecuador":
                return 27;
            case "Taiwan":
                return 28;
            case "Haiti":
                return 29;
            case "Columbia":
                return 30;
            case "Hungary":
                return 31;
            case "Guatemala":
                return 32;
            case "Nicaragua":
                return 33;
            case "Scotland":
                return 34;
            case "Thailand":
                return 35;
            case "Yugoslavia":
                return 36;
            case "El-Salvador":
                return 37;
            case "Trinadad&Tobago":
                return 38;
            case "Peru":
                return 39;
            case "Hong":
                return 40;
            case "Holand-Netherlands":
                return 41;
            default:
                return 0;
        }
    }

    public static int is5K(String income) {
        switch (income) {
            case ">":
                return 2;
            case "<":
                return 1;
            default:
                return 0;
        }
    }
}
